package com.jinxin.platform.cdcardpassmgr.service.impl;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdcardpassmgr.bean.CdcardpassmgrPosition;
import com.jinxin.platform.cdcardpassmgr.mapper.CdcardpassmgrPositionMapper;
import com.jinxin.platform.cdcardpassmgr.service.ICardpassmgrPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-10-19
 * @Author: Lingnan
 **/
@Service
public class CardpassmgrPositionServiceImpl implements ICardpassmgrPositionService {
    @Autowired
    private CdcardpassmgrPositionMapper positionMapper;

    @Override
    public JsonResult saveOrUpdate(CdcardpassmgrPosition record) {
        if (record == null || StringUtils.isEmpty(record.getCarId())){
            return JsonResult.error("参数错误，操作失败");
        }
        int count;
        String msg = "";
        Long carId = record.getCarId();
        CdcardpassmgrPosition position = positionMapper.selectByKey(carId);
        if(position == null){
            count = positionMapper.insert(record);
            msg = "新增成功";
        }else {
            count = positionMapper.updateByKey(record);
            msg = "更新成功";
        }
        if(count > 0){
            return JsonResult.ok(msg,"");
        }else {
            return JsonResult.error("操作失败，请重试");
        }
    }
}
